<template>
  <div class="delAll">
    <el-button type="info" @click="moveToTrash">
      <i class="el-icon-delete"></i> 批量删除
    </el-button>
  </div>
</template>

<script>
  import { mapMutations, mapActions } from 'vuex'
  import { commodityDelAll } from '../../http/apis/goodsApi/commodity.js'
  export default {
    components: {},
    props: {
      checkVal: Array,
    },
    data() {
      return {
      };
    },
    watch: {},
    computed: {},
    methods: {
      ...mapMutations('goodsStore', ['Goodslist']),
      ...mapActions('goodsStore', ['GetCounts']),
      moveToTrash() {
        this.$confirm('此操作将删除选中信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(() => {
            commodityDelAll(this.checkVal)
              .then(() => {
                this.$message({
                  type: "success",
                  message: "批量删除成功",
                });
              })
              .catch(() => {
                this.$message({
                  type: "error",
                  message: "批量删除失败",
                });
              });
              
            this.$router.push('/goods/commodity/commodityMsg')
            this.GetCounts({ database: 'goods' })
            this.Goodslist();
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
              showClose: true,
            });
          });
      },
    },
    created() { },
    mounted() { }
  };
</script>
<style lang="scss" scoped>
</style>